package com.ck.springboot.rabbitmq.conf;

import com.ck.springboot.rabbitmq.constants.Constant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author : lpc
 * @CreateTime : 2019/9/3
 * @Description :
 **/
@Configuration
public class DirectRabbitConfig {

    //队列 起名：directQueue
    @Bean
    public Queue TestDirectQueue() {
        return new Queue(Constant.DIRECT_QUEUE,true);
    }

    //Direct交换机 起名：directExchange
    @Bean
    DirectExchange TestDirectExchange() {
        return new DirectExchange(Constant.DIRECT_EXCHANGE);
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：directRouting
    @Bean
    Binding bindingDirect() {
        return BindingBuilder.bind(TestDirectQueue()).to(TestDirectExchange()).with(Constant.DIRECT_ROUTING);
    }
}
